<?php
class WebUser extends CWebUser {
	protected function afterLogin($fromCookie) {
	}

	protected function afterLogout() {
	}
}

class YiiJoomlaAdapter{
	public static function syncLogin() {
		//hack session code
		$session=Yii::app()->session;
		$sessionId=$session->getSessionID();
		//		$sessionData=array();
		//		foreach ($session as $k=>$v) {
		//			$sessionData[$k]=$v;
		//		}
		//		$session->writeSession($sessionId,$sessionData);
//		$sessionName= session_name();
//session_write_close();
//session_start();
//session_destroy();
//session_start();
//session_id(md5($sessionId));
//session_name(md5($sessionName));
		//session_set_save_handler(
//		array($this,'openSession'),
//		array($this,'closeSession'),
//		array($this,'readSession'),
//		array($this,'writeSession'),
//		array($this,'destroySession'),
//		array($this,'gcSession'));

		define('_JEXEC',1);
		$jbase=dirname(dirname(Yii::app()->basePath)).DIRECTORY_SEPARATOR
		.'joomla';
		define('JPATH_BASE', $jbase);
		define('DS', DIRECTORY_SEPARATOR);
		spl_autoload_unregister(array('YiiBase','autoload'));
		include_once( $jbase.DIRECTORY_SEPARATOR.'includes'.DIRECTORY_SEPARATOR.'defines.php' );
		include_once JPATH_LIBRARIES.'/loader.php';
		include_once ( $jbase.DIRECTORY_SEPARATOR.'includes'.DIRECTORY_SEPARATOR.'framework.php' );
		$mainframe =& JFactory::getApplication('site');
		$mainframe->initialise();
		$credentials = array();
		$credentials['username'] = 'admin';
		$credentials['password'] = 'admin';
		$error = $mainframe->login($credentials);

	}
}